package net.mycrub.bitwise.core;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

@Root
public class Brain implements ILayer {
    @Attribute
    private String name;
    @Attribute
    private int generation;
    @Element
    private ILayer layer;

    public Brain(@Attribute(name = "name") String name,
            @Element(name = "layer") ILayer layer) {
        this.name = name;
        this.layer = layer;
    }

    public String getName() {
        return name;
    }

    public ILayer getLayer() {
        return layer;
    }

    public Brain combine(ILayer partner) {
        if (partner instanceof Brain) {
            Brain b = new Brain(name, layer.combine(((Brain)partner).layer));
            b.generation++;
            return b;
        }
        else {
            throw new IllegalArgumentException(
                    "Layers are not compatible for combination "
                            + this.getClass().getName() + "/"
                            + partner.getClass().getName());
        }
    }

    public ILayer duplicate() {
        return new Brain(name, layer.duplicate());
    }

    public int getInputSize() {
        return layer.getInputSize();
    }

    public int getOutputSize() {
        return layer.getOutputSize();
    }

    public void mutate() {
        layer.mutate();
    }

    public double[] process(double[] input, IRetroActionCallback callback) {
        return layer.process(input, callback);
    }

    public double[] process(double[] input) {
        return layer.process(input);
    }
    
}
